const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const rootPath = process.cwd()
module.exports = {
  module: {
    loaders: [
      {
        test: /\.css$/,
        include: /node_modules/,
        // use: [ 'style-loader', 'css-loader' ]
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [
            {
              loader: 'css-loader',
              options: {
                minimize: true
              }
            }
          ]
        })
      },
      {
        test: /\.less$/,
        include: [path.resolve('./src/')],
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [
            {
              loader: 'css-loader',
              options: {
                minimize: true,
                module: true,
                localIdentName: '[local]---[hash:base64:8]'
              }
            },
            {
              loader: 'postcss-loader',
              options: {
                config: {
                  path: rootPath + '/postcss.config.js'
                }
              }
            },
            {
              loader: 'less-loader',
              options: { javascriptEnabled: true }
            }
          ]
        })
      },
      {
        test: /\.(png|jpg|gif)/,
        include: path.resolve('./images/'),
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 20000,
              outputPath: 'static/front/images/'
            }
          }
        ]
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/,
        include: path.resolve('./src/'),
        query: {
          presets: ['es2015', 'stage-0', 'react']
        }
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: rootPath + '/src/index.html',
      title: 'index',
      filename: 'templates/index.html',
      inject: true,
    }),
    new ExtractTextPlugin('static/front/css/app.[hash].css')
  ],
  resolve: {
    alias: {
      '@': path.join(rootPath, 'src')
    },
  }
}
